﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interactivity;
//using Microsoft.Expression.Interactivity.Core;

namespace WpfWordsLearner
{
	public class EnterToTabBehavior : Behavior<UIElement>
	{
		public EnterToTabBehavior()
		{
		}

		protected override void OnAttached()
		{
			base.OnAttached();
			AssociatedObject.PreviewKeyDown += new KeyEventHandler(AssociatedObject_PreviewKeyDown);
		}

		protected override void OnDetaching()
		{
			base.OnDetaching();
			AssociatedObject.PreviewKeyDown -= new KeyEventHandler(AssociatedObject_PreviewKeyDown);
		}

		private void AssociatedObject_PreviewKeyDown(object sender, KeyEventArgs e)
		{
			if (e.Key == Key.Enter)
			{
				e.Handled = true;
				AssociatedObject.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
			}
		}
	}
}